home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 5B2Y36 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.7 KB  |  64 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.event.InputEvent;
  7. import java.awt.event.MouseAdapter;
  8. import java.awt.event.MouseEvent;
  9. import java.io.IOException;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.Serializable;
  13.  
  14. class Autoscroller extends MouseAdapter implements Serializable {
  15.    transient MouseEvent event;
  16.    transient Timer timer;
  17.    JComponent component;
  18.  
  19.    Autoscroller(JComponent c) {
  20.       if (c == null) {
  21.          throw new IllegalArgumentException("component must be non null");
  22.       } else {
  23.          this.component = c;
  24.          this.timer = new Timer(100, new AutoScrollTimerAction(this));
  25.          this.component.addMouseListener(this);
  26.       }
  27.    }
  28.  
  29.    public void mouseDragged(MouseEvent e) {
  30.       Rectangle visibleRect = this.component.getVisibleRect();
  31.       boolean contains = visibleRect.contains(e.getX(), e.getY());
  32.       if (contains) {
  33.          if (this.timer.isRunning()) {
  34.             this.stop();
  35.          }
  36.       } else {
  37.          Point screenLocation = this.component.getLocationOnScreen();
  38.          this.event = new MouseEvent(this.component, ((AWTEvent)e).getID(), ((InputEvent)e).getWhen(), ((InputEvent)e).getModifiers(), e.getX() + screenLocation.x, e.getY() + screenLocation.y, e.getClickCount(), e.isPopupTrigger());
  39.          if (!this.timer.isRunning()) {
  40.             this.timer.start();
  41.          }
  42.       }
  43.  
  44.    }
  45.  
  46.    public void mouseReleased(MouseEvent e) {
  47.       this.stop();
  48.    }
  49.  
  50.    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
  51.       s.defaultReadObject();
  52.       this.timer = new Timer(100, new AutoScrollTimerAction(this));
  53.    }
  54.  
  55.    void stop() {
  56.       this.timer.stop();
  57.       this.event = null;
  58.    }
  59.  
  60.    private void writeObject(ObjectOutputStream s) throws IOException {
  61.       s.defaultWriteObject();
  62.    }
  63. }
  64.